# -*- coding: utf-8 -*-
"""
Created on Wed May 27 22:28:13 2020

@author: zhryyshr
"""

import requests
import json
import time
import fake_useragent as fu    #动态的浏览器标识
ua = fu.UserAgent()
header = {'User-Agent':ua.random }
from bs4 import BeautifulSoup
import pandas as pd
import numpy as np
import os
os.chdir(r"D:\Document\doing")
print('完成')


url_1 = "http://datainterface.eastmoney.com/EM_DataCenter/JS.aspx?type=SR&sty=ZF&st=5&sr=-1&p="
page=str(1)
url_2 = "&ps=50&stat=0"
url = url_1+page+url_2
response = requests.get(url,headers= header)

datastr = response.text[2:-2]+','



for page in np.arange(2,79,1):
    time.sleep(1)
    url = url_1+str(page)+url_2
    res = requests.get(url,headers = header)
    datastr = datastr+ res.text[2:-2]+','
    
datastr = datastr[:-1]
with open('增发数据.txt','w') as file:
    file.write(datastr)
    file.close()

b = datastr.split('","')
b[0]=b[0][1:]
b[-1] = b[-1][:-1]

c = []
for item in b:
    c.append(item.split(','))
    
df = pd.DataFrame(c)
df.head(10)

df.to_csv("东方财富增发数据.csv")